#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int Maxn=4e5+5;
int q;
struct node{
	int l,r;
}p[Maxn];
set<int>s;
int n,a[Maxn],b[Maxn];
namespace sub1{
	inline void sol(){
		int sum1=0,sum2=0,ans=0;
		for(int i=1;i<=n;i++){
			sum1+=a[i];sum2+=a[n-i+1];
			p[i]={sum1,sum2-1};
			if(sum1==sum2)break;
			ans+=sum2-sum1-max(0ll,p[i-1].r-p[i].l+1);
		}printf("%lld\n",ans);
	}
	inline void solve(){
		while(q--){
			int x=read();
			if(s.find(x)!=s.end()){
				s.erase(s.find(x));
				int n1=0;
				for(int i=1;i<=n;i++)(a[i]==x?0:a[++n1]=a[i]);
				n=n1;
			}
			else{
				s.insert(x);a[++n]=x;
				for(int i=n-1;i;i--)
					if(a[i]>a[i+1])swap(a[i],a[i+1]);
					else break;
			}
			sol();
		}
	}
}
signed main(){
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	q=read();
	if(q<=3e4)sub1::solve(),exit(0);
	int sum=0;
	while(q--){
		int x=read();
		if(s.find(x)!=s.end()){
			sum-=x;
			s.erase(s.find(x));
		}
		else{
			sum+=x;
			s.insert(x);
		}
		printf("%lld\n",sum-2*(*s.begin()));
	}
	return 0;
}
/*
-O2 -std=c++14 -static -Wl,--stack=21000000000
*/
